/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pdlv2;
import graph.*;
import query.*;
/**
 *
 * @author Gonzalo
 */
public class PDLv2 {
    private String dir;
    private Graph g;
    private Schema schema;
    private Parser parser;
    public PDLv2(String s){
        dir=s;
        parser=new Parser();
        open();
    }

    public void open(){
        //Abrir Schema
        schema=new Schema(dir);
        //A partir del Schema, crear Graph
        g=schema.getGraph();
        //Crear Disks y Edges
        //Asignar Edges a Graph
    }
    public void close(){
        //Cerrar Graph
        //Cerrar Schema
        g.flush();
        schema.close();
    }

    public long ejecutar(Query Q){
            return Q.ejecutar(g).count();
    }

    public long ejecutar(String Q){
            return parser.getQuery(Q).ejecutar(g).count();
    }

    public void createEdgeType(String label){
        schema.createEdgeType(label);
    }
    public void createAttributeType(String label,String type){
        schema.createAttributeType(label,type);
    }
    public void createAttributeLong(String label){
        schema.createAttributeType(label,"long");
    }
    public void createAttributeString(String label){
        schema.createAttributeType(label,"string");
    }
    public void ejecutarDLL(DDL D){
            D.ejecutar(schema);
    }
    public void ejecutarDebug(Debug D){
            D.ejecutar(schema);
    }
    public Nodes ejecutarQuery(Query Q){
            return Q.ejecutar(g);
    }
    public Nodes ejecutarDML(DML D){
            return D.ejecutar(g);
    }
    public String getAttributeString(long nodo,String attr){
        return g.getAttribute(nodo,attr,true);
    }
    public long getAttributeLong(long nodo,String attr){
        return g.getAttribute(nodo,attr);
    }
    public long findNodoWhere(String sttr,String v){
        return g.findNodoWhere(sttr,v);
    }
    public long findNodoWhere(String sttr,long v){
        return g.findNodoWhere(sttr,v);
    }
    public void print(Nodes R){
        int i=0;
        for(R.init();R.notNull() && i<10;R.next()){
            debug(g.printNode(R.getActual()));
            i++;
        }
    }

    public long newNode(){
        return g.newNode();
    }
    public long newNodes(long n){
        return g.newNodes(n);
    }
    public long numNodes(){
        return g.countNodes();
    }
    public boolean newEdge(String a,long desde,long hasta){
        return g.addEdge(a, desde, hasta);
    }
    public boolean setAttribute(long nodo,String attr,String v){
        return g.setAttribute(nodo, attr, v);
    }
    public boolean setAttribute(long nodo,String attr,long v){
        return g.setAttribute(nodo, attr, v);
    }
    public void flush(){
        g.flush();
    }
    public void debug(long s){g.debug(s);}
    public void debug(String s){g.debug(s);}
    public void debug(Exception e){g.debug(e);}
    public void speed(String s){g.speed(s);}
    public void speed(){g.speed();}

}
